/*!
* Ext JS Library 3.2.1
* Copyright(c) 2006-2010 Ext JS, Inc.
* licensing@extjs.com
* http://www.extjs.com/license
*/
/**
* @class Ext.ux.RouteCompareChart
* @extends Ext.Panel
* @author Shea Frederick
*/
Ext.ux.RouteCompareChartPanel = Ext.extend(Ext.Panel, {
    initComponent: function() {
        var defConfig = {
            plain: true,
            zoomLevel: 3,
            yaw: 180,
            pitch: 0,
            zoom: 0,
            gmapType: 'map',
            border: false,
            layout: 'border'
        };
        var me = this;
        this.leftChart, this.rightChart;

        this.leftChart = new Ext.ux.GMapPanel({
            region: 'center',
            zoomLevel: 14,
            gmapType: 'map',
            border: true,
            listeners: {
                resize: function() {
                    me.rightChart.onResize();
                },
                afterRender: function() {
                    me.leftMapController = new MSGMap(this.getMap(), true, null, gmapurl);
                    me.leftMapController.setCenter(new GLatLng(22, 114), 14);
                    setTimeout(function() {
                        me.leftMapController.checkResize();
                        me.leftMapController.showCommonRoute(me.defined_route.route_data);
                    }, 300);
                }
            }
        });

        this.rightChart = new Ext.ux.GMapPanel({
            region: 'east',
            width: '50%',
            gmapType: 'map',
            border: true,
            split: true,
            listeners: {
                resize: function() {
                    me.leftChart.onResize();
                },
                afterRender: function() {
                    me.rightMapController = new MSGMap(this.getMap(), true, null, gmapurl);
                    me.rightMapController.setCenter(new GLatLng(22, 114), 14);
                    var totalDistance = me.rightMapController.showDeviateRouteAndParking(me.real_route.points, function(content) {
                        msgWarning(content);
                    });

                    me.setTitle(me.title + "(" + _TxtTotalDeviate + totalDistance + ")");
                }
            }
        });

        defConfig.items = [this.leftChart, this.rightChart];
        Ext.applyIf(this, defConfig);
        Ext.ux.RouteCompareChartPanel.superclass.initComponent.call(this);
    },

    afterRender: function() {
        var wh = this.ownerCt.getSize();
        Ext.applyIf(this, wh);
        Ext.ux.RouteCompareChartPanel.superclass.afterRender.call(this);

    },
    onResize: function(w, h) {
        if (typeof this.leftChart.getMap() == 'object') {
            this.leftChart.getMap().checkResize();
        }
        if (typeof this.rightChart.getMap() == 'object') {
            this.rightChart.getMap().checkResize();
        }
        Ext.ux.RouteCompareChartPanel.superclass.onResize.call(this, w, h);

    },
    setSize: function(width, height, animate) {
        if (typeof this.leftChart.getMap() == 'object') {
            this.leftChart.getMap().checkResize();
        }
        if (typeof this.rightChart.getMap() == 'object') {
            this.rightChart.getMap().checkResize();
        }
        Ext.ux.GMapPanel.superclass.setSize.call(this, width, height, animate);
    },
    getLeftMapPanel: function() {
        return this.leftChart;
    },
    getRightMapPanel: function() {
        return this.rightChart;
    },
    getLeftMapController: function() {
        return this.leftMapController
    },
    getRightMapController: function() {
        return this.rightMapController
    }
});

Ext.reg('routecomparechartpanel', Ext.ux.GMapPanel);